package com.lzx.ai.utils;

import com.huaban.analysis.jieba.JiebaSegmenter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author 程序员星星
 * @date 2023/4/28
 * @Description
 */
public class JiebaKeywordExtractor {
    private static final JiebaSegmenter segmenter = new JiebaSegmenter();

    public static List<String> extractKeywords(String text) {
        try {
            List<String> keywords = new ArrayList<>();
            List<String> segments = segmenter.sentenceProcess(text);
            for (String segment : segments) {
                if (segment.length() > 1) {
                    keywords.add(segment);
                }
            }
            return keywords;
        } catch (Exception e) {
            return Collections.emptyList();
        }
    }
}
